/**
 * @file cmap.h
 * @brief Definisce la struttura dati Map Concorrenziale.
 *
 * Complete description of this file.
 *
 * @date Mar 16, 2012
 * @author Francesco Corvino
 */

#ifndef CMAP_H_
#define CMAP_H_

#include <pthread.h>
#include "dynArray.h"

/**
 * @brief permette di scorrere gli elementi della mappa.
 *
 * @param map puntatore a un oggetto CMap da controllare.
 * @param index puntatore a un'intero da utilizzare come indice.
 * @param tmp puntatore che conterrà l'elemento restituito.
 */
#define CMAP_FOREACH(map,index,tmp) \
		while((tmp = CMap_getNext((map),(index)))!=NULL)

typedef struct CMapElem_{
	int key;
	size_t dimdata;
	void *data;
	pthread_mutex_t synelem;
} CMapElem;

typedef struct CMap_ {
	DynArray values;
	pthread_mutex_t synarr;
} CMap;

void CMap_init(CMap * cmap);

void CMap_destroy(CMap * cmap);

void* CMap_get(CMap * cmap, const int key);

void* CMap_getNext(CMap *cmap, int *index);

void * CMap_getByIndex(CMap * cmap, const int index);

int CMap_size(CMap * cmap);

void CMap_set(CMap * cmap, const int key, void * data, size_t dim);

int CMap_has(CMap * cmap, const int key);

int CMap_remove(CMap * cmap, const int key);

//int CMap_operateOn(CMap * cmap, const int key, int (*op)(void*));

DynArray* CMap_toArray(CMap * cmap, size_t dimSingleElem);

int CMap_StringHash(char * strToHash);

#endif /* CMAP_H_ */
